package com.yanmaohu.nikita.data.structure;

import com.yanmaohu.nikita.data.expression.Expression;
import com.yanmaohu.nikita.data.expression.NameExpression;

/**
 * @author Bright Lee
 */
public final class VariableMemberInstance implements MemberInstance {

    private NameExpression variableName;
    private Expression variableValue;

    public VariableMemberInstance(NameExpression variableName,
                                  Expression variableValue) {
        this.variableName = variableName;
        this.variableValue = variableValue;
    }

    @Override
    public int getBeginIndex() {
        return variableName.getBeginIndex();
    }

    @Override
    public int getEndIndex() {
        if (variableValue != null) {
            return variableValue.getEndIndex();
        }
        return variableName.getEndIndex();
    }

    public NameExpression getVariableName() {
        return variableName;
    }

    public Expression getVariableValue() {
        return variableValue;
    }

}
